<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Poll/classes/PhpFox_ComponentView.class.php, $Author:  $ */



/** Component for viewing the poll
 *
 * @version $Id: PhpFox_ComponentView.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.poll
 */
class PhpFox_Mod_Poll_ComponentView extends BaseComponent
{
    function process()
    {
    	App::membersOnly();

        $oPollItem = &$this->_oModule->getItem('Poll');
        /* @var $oPollItem PhpFox_Mod_Poll_ItemPoll */
        $oPollService = &$this->_oModule->getService('Poll');
        /* @var $oPollService PhpFox_Mod_Poll_ServicePoll */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oTpl = &$this->_oModule->getTemplate();
        $oUrl = &App::getUrl();
        $oReq = &App::getRequest();

        $oSecurityService->checkPerm('poll', array('read_only', 'full'));
        $oSecurityService->checkAccess('poll');
        $iPollId = $oReq->getInt('id');

        $oPollItem->load($iPollId);
        $sUser = $oSecurityService->getCurrentUserLogin();
        if (!$oPollService->isUserCanVote($iPollId) && ($oPollItem->aData['user'] != $sUser))
        {
        	if (!App::isStaff())
        	{
            	App::gotoUrl('public.poll');
        	}
        }
        list($aAnswers, $iTotal) = $oPollService->makePollPercents($oPollItem->aData);
        list($aVoters, $iCnt) = $oPollService->getVoters($iPollId);

        $oTpl->assign(array(
            'aAnswers' => $aAnswers,
            'aPoll'    => $oPollItem->aData,
            'aVoters'  => $aVoters,
            'iTotal'   => $iTotal,
        ));
        return $oTpl->fetch('View.html');
    }
}
?>